import { View, Text } from '@tarojs/components'
import { useEffect, useRef } from 'react'
import { connect, useDispatch } from 'react-redux'
import './index.scss'

function App(props) {

    const { showMessage } = props
    const dispatch = useDispatch()
    const messageShow = useRef<any>(null)

    useEffect(() => {
        messageShow.current.style.display = showMessage
        if (showMessage === 'block') {
            setTimeout(() => {
                dispatch({
                    type: 'SHOW_TOAST',
                    data: 'none'
                })
            }, 2000);
        }
    }, [showMessage])

    return (
        <View className='custom_toast_container' ref={messageShow}>
            <View className='custom_toast_text'>请前往电脑端查看详情</View>
        </View>
    )
}

const mainProps = ({ commonData }) => {
    return {
        showMessage: commonData.showMessage,
    }
}

export default connect(mainProps)(App)